Skip to content

fix(animation): settle promises after cancellation - #2280

Open
lanqing431 wants to merge 1 commit into
antvis:masterfrom
lanqing431:fix/settle-cancelled-animation-promises
Open

lanqing431 wants to merge 1 commit into
antvis:masterfrom
lanqing431:fix/settle-cancelled-animation-promises

Conversation

@lanqing431

Copy link
Copy Markdown

Related issue

Fixes #1947.

Background and solution

Cancelling an animation clears its start time. The previous pending check treated the cleared start time as pending even after the animation became idle, so the promise update never observed the idle transition. Animations that were still in their delay could also return early from cancellation.

Use the animation's idle state when deciding whether it can be pending or cancelled. Cancelled promises reject with AbortError, and the next read of finished returns a fresh promise. This follows the Web Animations cancellation steps.

Validation

  • Two regression cases cover cancellation before the first frame, with and without a delay. Both fail on the previous implementation.
  • The existing running-animation snapshot now asserts that cancellation settles finished.
  • Ran the complete unit suite on Node 20 (283 passed, 36 skipped by the suite), the workspace build, ESLint and Prettier.
  • In Chromium, the built G Canvas renderer and the native Animation API had the same cancellation state and promise results for both delays.

@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 428862d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

动画api中,如果在动画执行的过程中,调用cancel方法,会导致动画的finished Promise 不进入后续状态

1 participant